package com.bz.util;

import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;
import java.io.File;
import java.util.Arrays;

@Slf4j
public class SocketUtil {

    public static boolean isValidFileType(String filename) {
        // 实现文件类型验证逻辑，例如只允许图片类型
        String[] allowedExtensions = {"jpg", "jpeg", "png", "gif"};
        String extension =  FileUtil.extName(filename).toLowerCase();
        return Arrays.asList(allowedExtensions).contains(extension);
    }

    public static void generateThumbnailAsync(String filePath) {
        // 异步生成缩略图的逻辑
        new Thread(() -> {
            try {
                Thumbnails.of(new File(filePath))
                        .size(200, 200)
                        .toFile(filePath + "_thumb.jpg");
            } catch (Exception e) {
                log.error("生成缩略图时发生错误: {}", e.getMessage(), e);
            }
        }).start();
    }

}
